#include <cstdio>
#include <cstring>

#include <algorithm>

using namespace std;

char buff[1000000];

struct bigint {
	long long hi, lo;

	void read() {
		int data[26]; memset(data, 0, sizeof(data));

		scanf("%s", buff);

		int at = 0, leng = strlen(buff);
		while( at < leng && buff[at] == '0' )
			++at;

		for( int p = leng-1, k = 0; p >= at; --p, ++k )
			data[k] = buff[p] - '0';

		lo = hi = 0;
		for( int i = 12; i >= 0; --i ) lo = lo*10 + data[i];
		for( int i = 25; i > 12; --i ) hi = hi*10 + data[i];
	}

	void out() {
//		printf( "fuck = %I64d%I64d\n", hi, lo );

		if( hi ) {
			printf( "%lld", hi );
			printf( "%013lld\n", lo );
		} else {
			printf( "%lld\n", lo );
		}
	}
};

bool operator < ( const bigint& u, const bigint& v )
{
	if( u.hi != v.hi ) return u.hi > v.hi;
	if( u.lo != v.lo ) return u.lo > v.lo;
	return false;
}

int n;
bigint A[1000005];

int main( void )
{
	freopen( "input.txt", "r", stdin );

	scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		A[i].read();
//		A[i].out();
	}

	sort(A, A + n);
	for( int i = 0; i < 10; ++i )
		A[i].out();

	return 0;
}
